package cn.itcast.wanxinp2p.consumer.service.impl;

import cn.itcast.wanxinp2p.api.consumer.model.BankCardDTO;

import cn.itcast.wanxinp2p.consumer.domain.BankCard;
import cn.itcast.wanxinp2p.consumer.domain.Consumer;
import cn.itcast.wanxinp2p.consumer.mapper.BankCardMapper;
import cn.itcast.wanxinp2p.consumer.mapper.ConsumerMapper;
import cn.itcast.wanxinp2p.consumer.service.BankCardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> implements BankCardService {

    @Autowired
    BankCardMapper bankCardMapper;
    @Autowired
    ConsumerMapper consumerMapper;
    @Override
    public BankCardDTO getByConsumerId(Long consumerId) {
   		//TODO 根据用户id查询银行卡信息
        BankCard bankCard = bankCardMapper.getByConsumerId(consumerId);
        return convertBankCardEntityToDTO(bankCard);
    }
    @Override
    public BankCardDTO getByCardNumber(String cardNumber) {
		//TODO 根据卡号查询银行卡信息
        BankCard bankCard = bankCardMapper.getByCardNumber(cardNumber);
        return convertBankCardEntityToDTO(bankCard);
    }

    @Override
    public Integer saveBankCard(BankCard bankCard) {

        return bankCardMapper.saveBankCard(bankCard);
    }

    @Override
    public Integer updateBankCard(BankCard bankCard) {
        return bankCardMapper.updateBankCard(bankCard);
    }


    private BankCardDTO convertBankCardEntityToDTO(BankCard bankCard){
        if(bankCard==null){
            return null;
        }
        BankCardDTO bankCardDTO=new BankCardDTO();
        BeanUtils.copyProperties(bankCard,bankCardDTO);
        return bankCardDTO;
    }


}